import 'dart:io';

import 'package:flutter/material.dart';
import 'package:download_learn/download_learn.dart';

class DownloadPage extends StatefulWidget {
  const DownloadPage({super.key});

  @override
  State<DownloadPage> createState() => _DownloadPageState();
}

class _DownloadPageState extends State<DownloadPage> {
  get _getBtn => ElevatedButton(onPressed: onPressed, child: Text('下载'));
  File? file;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(children: [
        _getBtn,
        if(file!=null) Image.file(file!)
      ],),
    );
  }

  void onPressed() async{
    String? path;
     path = await HiDownLoad().download(downLoadUrl: 'https://images.pexels.com/photos/4836103/pexels-photo-4836103.jpeg?auto=compress&cs=tinysrgb&w=600&lazy=load',
        fileName: 'test', listener: (int total, int received, bool done){
            if(done){
              setState(() {
                file = File(path!);
              });
            }
        });
  }
}
